@extends('layouts.admin')

@section('title', '人员管理-添加')

@section('style')
    <link rel="stylesheet" type="text/css" href="{{asset('lib/bootstrap/css/bootstrap.min.css')}}" />
    <link rel="stylesheet" type="text/css" href="{{asset('lib/bootstrap/css/bootstrap-combobox.css')}}" />
    <link rel="stylesheet" type="text/css" href="{{asset('lib/bootstrap/css/multiple-select.css')}}" />
@endsection

@section('content')
    <article class="page-container">
        <form action="" method="post" class="form form-horizontal" id="form-department-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>手机：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" value="" placeholder="" id="phone" name="phone" autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>密码：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="password" class="input-text" value="" placeholder="" id="password" name="password" autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>真实姓名：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>性别：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <div class="skin-minimal">
                        <div class="radio-box">
                            <input type="radio" id="radio-1" name="sex" value="M">
                            <label for="radio-1">男</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" id="radio-2" name="sex" checked value="F">
                            <label for="radio-2">女</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>邮箱：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="email" class="input-text" value="" placeholder="" id="email" name="email">
                </div>
            </div>
            {{--<div class="row cl">--}}
                {{--<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>工号：</label>--}}
                {{--<div class="formControls col-xs-8 col-sm-10">--}}
                    {{--<input type="text" class="input-text" value="" placeholder="" id="work_no" name="work_no">--}}
                {{--</div>--}}
            {{--</div>--}}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>微信号：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" value="" placeholder="" id="wx_no" name="wx_no">
                </div>
            </div>
            {{--<div class="row cl">--}}
                {{--<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>直属领导：</label>--}}
                {{--<div class="formControls col-xs-8 col-sm-10">--}}
                    {{--<select class="combobox input-large form-control" name="direct_leader_user_id" id="direct_leader_user_id">--}}
                        {{--<option value="0" selected="selected">--无--</option>--}}
                        {{--@foreach ($users['data'] as $user)--}}
                            {{--<option value="{{$user['id']}}">{{$user['name']}}</option>--}}
                        {{--@endforeach--}}
                    {{--</select>--}}
                {{--</div>--}}
            {{--</div>--}}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>部门：</label>
                <div class="formControls col-xs-4 col-sm-5">
                    <select class="combobox input-large form-control" name="major_department_id" id="major_department_id">
                        <option value="0" selected="selected">--无--</option>
                        @foreach ($departments['data'] as $department)
                            <option value="{{$department['id']}}">{{$department['name']}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="formControls col-xs-4 col-sm-5">
                    <select multiple="multiple" class="multiple w94" name="assist_department_ids[]" id="assist_department_ids">
                        @foreach ($departments['data'] as $department)
                            <option value="{{$department['id']}}">{{$department['name']}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>岗位：</label>
                <div class="formControls col-xs-4 col-sm-5">
                    <select class="combobox input-large form-control" name="major_station_id" id="major_station_id">
                        <option value="0" selected="selected">--无--</option>
                        @foreach ($stations['data'] as $station)
                            <option value="{{$station['id']}}">{{$station['name']}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="formControls col-xs-4 col-sm-5">
                    <select multiple="multiple" class="multiple w94" name="assist_station_ids[]" id="assist_station_ids">
                        @foreach ($stations['data'] as $station)
                            <option value="{{$station['id']}}">{{$station['name']}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账号状态：</label>
                <div class="formControls col-xs-8 col-sm-10">
                    <div class="mt-20 skin-minimal">
                        <div class="radio-box">
                            <input type="radio" id="radio-11" value="1" name="account_status" checked>
                            <label for="radio-11">在职</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" id="radio-lock" value="2" name="account_status">
                            <label for="radio-lock">锁定</label>
                        </div>
                        <div class="radio-box">
                            <input type="radio" id="radio-21" value="3" name="account_status">
                            <label for="radio-21">离职</label>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
@endsection
@section('script')
    <script type="text/javascript" src="{{asset('lib/bootstrap/bootstrap-combobox.js')}}"></script>
    <script type="text/javascript" src="{{asset('lib/bootstrap/multiple-select.js')}}?snt=1"></script>
    <script>
        $('.combobox').combobox();
        $('#password').HuitogglePassword();
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $("#assist_department_ids").multipleSelect({
            filter: true,
            position: 'top',
            placeholder: "辅助部门"
        });
        $("#assist_station_ids").multipleSelect({
            filter: true,
            position: 'top',
            placeholder: "辅助岗位"
        });
        $(".input-text,.textarea").Huifocusblur();
        $(".textarea").Huitextarealength({
            minlength:0,
            maxlength:200.
        });
        //$('select').multipleSelect('setSelects', [1, 3]);
        $("#form-department-add").validate({
            rules:{
                name:{
                    required:true
                },
                password:{
                    required:true,
                    maxlength:20,
                    minlength:6
                },
                phone:{
                    required:true,
                    isTel:true
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var major_department_id=$("#major_department_id").val();
                var major_station_id=$("#major_station_id").val();
                if(major_department_id!='0'){
                    $("#assist_department_ids option[value='"+major_department_id+"']").attr("selected", false).removeAttr('selected');
                }
                if(major_station_id!='0'){
                    $("#assist_station_ids option[value='"+major_station_id+"'").attr("selected", false).removeAttr('selected');
                }
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{{url('system/user/add')}}",
                    success: function(data){
                        if(data['successFlag']==1){
                            layer_success_message("添加成功!");
                            setTimeout(function(){
                                parent.$(".btnSearch").click();
                                layer_close();
                            },500);
                        }else{
                            layer_error_message(data['msg']);
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer_error_message('添加失败!');
                    }
                });
            }
        });
    </script>
@endsection